From 4563cc37ec921e0705fba1b9caf20400bd75e138 Mon Sep 17 00:00:00 2001 From: robertl Date: Thu, 24 Dec 2009 20:43:27 +0000 Subject: [PATCH] Write heartrate and cadence in Garmin GPX extenstions. --- gpx.c | 60 ++++++++++++++++++++++++++++++++++------------------------- 1 file changed, 35 insertions(+), 25 deletions(-) diff --git a/gpx.c b/gpx.c index f983d5dd7..567d6d06b 100644 --- a/gpx.c +++ b/gpx.c @@ -1608,29 +1608,38 @@ gpx_write_common_position(const waypoint *waypointp, const char *indent) } static void -gpx_write_common_depth(const waypoint *waypointp, const char *indent) +gpx_write_common_extensions(const waypoint *waypointp, const char *indent) { - if (waypointp->depth != 0 || waypointp->temperature != 0) { - if (opt_humminbirdext || opt_garminext) { - gbfprintf(ofd, "%s\n", indent); - if (waypointp->depth != 0) { - if (opt_humminbirdext) - gbfprintf(ofd, "%s %f\n", - indent, waypointp->depth*100.0); - if (opt_garminext) - gbfprintf(ofd, "%s %f\n", - indent, waypointp->depth); - } - if (waypointp->temperature != 0) { - if (opt_humminbirdext) - gbfprintf(ofd, "%s %f\n", - indent, waypointp->temperature); - if (opt_garminext) - gbfprintf(ofd, "%s %f\n", - indent, waypointp->temperature); - } - gbfprintf(ofd, "%s\n", indent); + if (((opt_humminbirdext || opt_garminext) && (waypointp->depth != 0 || waypointp->temperature != 0)) + || (opt_garminext && (waypointp->heartrate != 0 || waypointp->cadence != 0))) { + gbfprintf(ofd, "%s\n", indent); + if (waypointp->depth != 0) { + if (opt_humminbirdext) + gbfprintf(ofd, "%s %f\n", + indent, waypointp->depth*100.0); + if (opt_garminext) + gbfprintf(ofd, "%s %f\n", + indent, waypointp->depth); + } + if (waypointp->temperature != 0) { + if (opt_humminbirdext) + gbfprintf(ofd, "%s %f\n", + indent, waypointp->temperature); + if (opt_garminext) + gbfprintf(ofd, "%s %f\n", + indent, waypointp->temperature); + } + if (opt_garminext && (waypointp->heartrate != 0 || waypointp->cadence != 0)) { + gbfprintf(ofd, "%s \n", indent); + if (waypointp->heartrate != 0) + gbfprintf(ofd, "%s %u\n", + indent, waypointp->heartrate); + if (waypointp->cadence != 0) + gbfprintf(ofd, "%s \n", + indent, waypointp->cadence); + gbfprintf(ofd, "%s \n", indent); } + gbfprintf(ofd, "%s\n", indent); } } @@ -1688,7 +1697,7 @@ gpx_waypt_pr(const waypoint *waypointp) /* MapSource doesn't accepts extensions from 1.0 */ garmin_fs_xml_fprint(ofd, waypointp); } - gpx_write_common_depth(waypointp, " "); + gpx_write_common_extensions(waypointp, " "); gbfprintf(ofd, "\n"); } @@ -1750,7 +1759,7 @@ gpx_track_disp(const waypoint *waypointp) fprint_xml_chain( fs_gpx->tag, waypointp ); } - gpx_write_common_depth(waypointp, " "); + gpx_write_common_extensions(waypointp, " "); gbfprintf(ofd, "\n"); } @@ -1805,7 +1814,7 @@ gpx_route_disp(const waypoint *waypointp) fprint_xml_chain( fs_gpx->tag, waypointp ); } - gpx_write_common_depth(waypointp, " "); + gpx_write_common_extensions(waypointp, " "); gbfprintf(ofd, " \n"); } @@ -1878,7 +1887,8 @@ gpx_write(void) if (opt_humminbirdext) gbfprintf(ofd, " xmlns:h=\"http://humminbird.com\"\n"); if (opt_garminext) - gbfprintf(ofd, " xmlns:gpxx=\"http://www.garmin.com/xmlschemas/GpxExtensions/v3\""); + gbfprintf(ofd, " xmlns:gpxx=\"http://www.garmin.com/xmlschemas/GpxExtensions/v3\"\n" + " xmlns:gpxtpx=\"http://www.garmin.com/xmlschemas/TrackPointExtension/v1\"\n"); gbfprintf(ofd, " xmlns=\"http://www.topografix.com/GPX/%c/%c\"\n", gpx_wversion[0], gpx_wversion[2]); if (xsi_schema_loc) { -- 2.30.2